package com.cqemme.activitiservice.receiver;

import com.cqemme.activitiservice.service.AlarmService;
import com.cqemme.comm.constraint.MqNames;
import com.cqemme.comm.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * 报警消费
 *
 * @author nejery
 */
@Component
@Slf4j
public class AlarmReceiver {

    private AlarmService alarmService;

    public AlarmReceiver(AlarmService alarmService) {
        this.alarmService = alarmService;
    }

    @RabbitListener(queues = MqNames.SCHOOL_HARDWARE_TO_ACTIVITI_ALARM)
    public void receiveAlarm(String msg){
        try {
            log.info("接收到报警消息:{}", msg);
            if(StringUtils.isNotBlank(msg)){
                alarmService.handleAlarm(msg);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }


}
